import type { Directive, DirectiveBinding } from 'vue'
import { menuStore } from '@/store/menu'
const permission: Directive = {
  mounted(el: HTMLElement, binding: DirectiveBinding): void {
    // console.log(el,'自定义指令')
    const { value } = binding
    // if (value == undefined) return;
    const store = menuStore()
    const { permissionBtn } = store
    // console.log('binding',binding,'permissionBtn==============',permissionBtn)

    if (!value) return;

    if (permissionBtn.length === 0) el.style.display = 'none'
    const flag = permissionBtn.some(it => it.code == value)
    if (flag) {
      el.style.display = 'auto'
    } else {
      el.style.display = 'none'
    }
  },
}

export default permission